home *** CD-ROM | disk | FTP | other *** search
- Path: anvil.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Zombies & Daemons
- Date: 28 Feb 1996 11:19:15 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4h29rjINNamh@anvil.ugrad.cs.ubc.ca>
- References: <3134348F.7526@citenet.net>
- NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
-
- In article <3134348F.7526@citenet.net>,
- Oliver Lavery <oliver@citenet.net> wrote:
- >I've just finished writting a daemon to handle generating web
- >pages from an Oracle database. When it executes, the parent forks a
- >number of children, all of which are bound to a network port. Each child
- >services requests in order etc. etc. works more or less like an apache
- >httpd...
- >
- > The problem is this: when one of the children dies for whatever
- >reason (usually a f*cked OCI call which makes the daemons session
- >unstable), the parent's sigcld handler forks a new child to keep a
- >consistent number of processes running. For some reason, however, the
- >dead child process lingers around as a zombie process ... how do I avoid
- >this?
-
- Your program is failing to observe the UNIX semantics for starting and
- finishing concurrent tasks. A forked process must be waited for with a special
- system call named wait(), or waitpid(). The man page for wait should tell you
- all the possibilities.
-
- The simiplest call, wait(), simply ``reaps'' the next available zombie. If no
- child has exited, it will block until a child does exit. You can call it from
- the signal handler. When a child that exited (or crashed or was terminated) is
- waited for, it ceases to be a zombie and is cleared from the system. The parent
- is able, through the wait() family of system calls, to obtain the exit status
- of the child, or if the child failed to exit properly, information such as
- whether the child made a core dump, etc.
-
- Get a book called ``Advanced Programming in the UNIX Environment''. Go to
- comp.unix.programmer. Read the FAQ. This is not really a comp.lang.c question.
- A competent C master who doesn't know anything about UNIX (if such a person
- exists) would not be able to answer.
-
- Also, learn about reliable signal handling with sigaction(), if you aren't
- using it already.
-
- > Also, does SunOS support copy on write memory pages? And do
- >zombie processes still use system resources?
-
- Yes. At the very _least_ they occupy a process table entry. Whether they occupy
- virtual space is a matter of implementation, but you know that since a zombie
- has a process ID, it is occupying at least a kernel process control block.
-
- I do believe that SunOS supports this. It should not concern you greatly unless
- you are doing an exec() in the child process just after the fork(). The
- system's manual page on fork() and vfork() should tell you whether vfork() is
- recommended for launching a child that immediately execs(). In modern UNIX
- systems, vfork() is obsoleted, since fork() is done using copy-on-write.
- --
-
-